package org.hqs.queueno.controller;


import org.hqs.queueno.common.JsonResult;
import org.hqs.queueno.pojo.QueueNo;
import org.hqs.queueno.service.QueueNoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Queue;

@RestController
@RequestMapping("/queueno")
public class QueueNoController {

    private final QueueNoService queueNoService;

    @Autowired
    public QueueNoController(QueueNoService queueNoService) {
        this.queueNoService = queueNoService;
    }

    @GetMapping
    public JsonResult<List<QueueNo>> getAllQueueNos() {
        return new JsonResult<>(queueNoService.getAllQueueNos());
    }

    @GetMapping("/{id}")
    public JsonResult<QueueNo>  getQueueNoById(@PathVariable int id) {
        return new JsonResult<>(queueNoService.getQueueNoById(id));
    }

    @PostMapping
    public JsonResult insertQueueNo(@RequestBody QueueNo queueNo) {
        int res = queueNoService.insertQueueNo(queueNo);
        if (res > 0) {
            return new JsonResult("200", "新增成功");
        }
        return new JsonResult("400", "似乎新增失败了");
    }

    @PutMapping("/{id}")
    public JsonResult updateQueueNo(@PathVariable int id, @RequestBody QueueNo queueNo) {
        queueNo.setId(id);
        int res = queueNoService.updateQueueNo(queueNo);
        if (res > 0) {
            return new JsonResult("200", "更新成功");
        }
        return new JsonResult("400", "似乎更新失败了");
    }

    @DeleteMapping("/{id}")
    public JsonResult deleteQueueNoById(@PathVariable int id) {
        int res = queueNoService.deleteQueueNoById(id);
        if (res > 0) {
            return new JsonResult("200", "删除成功");
        }
        return new JsonResult("400", "似乎删除失败了");
    }
}
